home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / test / connect.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-11  |  2.1 KB  |  76 lines

  1. //
  2. // "$Id: connect.cxx,v 1.4.2.1 1999/05/11 09:39:31 bill Exp $"
  3. //
  4. // PPP example program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Program to make a button to turn a ppp connection on/off.
  7. // You must chmod +s /usr/sbin/pppd, and put all the options
  8. // into /etc/ppp/options.
  9. //
  10. // Copyright 1998-1999 by Bill Spitzak and others.
  11. //
  12. // This library is free software; you can redistribute it and/or
  13. // modify it under the terms of the GNU Library General Public
  14. // License as published by the Free Software Foundation; either
  15. // version 2 of the License, or (at your option) any later version.
  16. //
  17. // This library is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20. // Library General Public License for more details.
  21. //
  22. // You should have received a copy of the GNU Library General Public
  23. // License along with this library; if not, write to the Free Software
  24. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  25. // USA.
  26. //
  27. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  28. //
  29.  
  30. #include <stdlib.h>
  31. #include <stdio.h>
  32. #include <unistd.h>
  33. #include <signal.h>
  34. #include <sys/wait.h>
  35.  
  36. #include <FL/Fl.H>
  37. #include <FL/Fl_Window.H>
  38. #include <FL/Fl_Toggle_Button.H>
  39.  
  40. int running;    // actually the pid
  41. Fl_Toggle_Button *Button;
  42.  
  43. void sigchld(int) {
  44.   waitpid(running, 0, 0);
  45.   running = 0;
  46.   Button->value(0);
  47. }
  48.  
  49. void cb(Fl_Widget *o, void *) {
  50.   if (((Fl_Toggle_Button*)o)->value()) {
  51.     if (running) return;
  52.     running = fork();
  53.     if (!running) execl("/usr/sbin/pppd","pppd","-detach",0);
  54.     else signal(SIGCHLD, sigchld);
  55.   } else {
  56.     if (!running) return;
  57.     kill(running, SIGINT);
  58.     waitpid(running, 0, 0);
  59.     running = 0;
  60.   }
  61. }
  62.  
  63. int main(int argc, char ** argv) {
  64.    Fl_Window window(100,50);
  65.    Fl_Toggle_Button button(0,0,100,50,"Connect");
  66.    Button = &button;
  67.    button.color(1,2);
  68.    button.callback(cb,0);
  69.    window.show(argc,argv);
  70.    return Fl::run();
  71. }
  72.  
  73. //
  74. // End of "$Id: connect.cxx,v 1.4.2.1 1999/05/11 09:39:31 bill Exp $".
  75. //
  76.